package com.meng.android.component;

import java.util.HashMap;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;

import com.meng.android.util.R;
import com.meng.android.util.UIUtils;

public class RowTextText extends LinearLayout implements BindingForm {

	EditText mEditText1, mEditText2;
	private String[] bindingElement;

	public RowTextText(Context context) {
		super(context);
	}

	public RowTextText(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@TargetApi(Build.VERSION_CODES.HONEYCOMB)
	public RowTextText(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	public static RowTextText create(Context context, String hint1, String hint2) {
		final RowTextText result = (RowTextText) UIUtils.inflater(context)
				.inflate(R.layout.row_text_text, null);
		result.mEditText1 = (EditText) result
				.findViewById(R.id.row_edit_text_1);
		result.mEditText2 = (EditText) result
				.findViewById(R.id.row_edit_text_2);
		result.mEditText1.setHint(hint1);
		result.mEditText2.setHint(hint2);
		return result;
	}

	public static RowTextText create(Context context, String hint1,
			boolean showOne) {
		final RowTextText view = create(context, hint1, null);
		if (showOne) {
			view.mEditText2.setVisibility(View.GONE);
		}
		return view;
	}

	@Override
	public void setBindingData(String[] strings) {
		this.bindingElement = strings;
	}

	@Override
	public HashMap<String, Object> getData() {
		HashMap<String, Object> result = new HashMap<String, Object>();
		for (int i = 0; i < bindingElement.length; i++) {
			final String key = bindingElement[i];
			if (i == 0) {
				result.put(key, mEditText1.getText().toString());
			} else if (i == 1) {
				result.put(key, mEditText2.getText().toString());
			}
		}
		return result;
	}

	@Override
	public void updateData(HashMap<String, Object> args) {

	}

}